package a4;

import java.util.LinkedList;

public class Sequences {
	
	private static int[][] sequences;
	private static int currentRow;

	public static int[][] getSequences(int[] possibilities) {
		
		int nbrPaths = 1;
		
		for (int i=0; i<possibilities.length; i++){
			nbrPaths *= possibilities[i];
		}
		
		sequences = new int[nbrPaths][possibilities.length];
		currentRow = 0;

		nextSequence(possibilities, possibilities.length, new LinkedList<Integer>());
		
		return sequences;
		
	}

	public static void nextSequence(int[] possibilities, int n, LinkedList<Integer> sequence) {
		if (n != 0) {
			for (int i = 0; i < possibilities[n - 1]; i++) {
				sequence.push(i);
				nextSequence(possibilities, n - 1, sequence);
				sequence.pop();
			}
		} else {
			for (int i=0; i<sequence.size(); i++){
				sequences[currentRow][i]=sequence.get(i);
			}
			currentRow++;
		}
	}

}
